<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>vue-resource & interceptors</title>
  <script src="js/vue.js"></script>
  <script src="js/vue-resource.js"></script>
</head>

<body>
  <h1>vue-resource & interceptors</h1>
  <div id="app">

  </div>
  <script>
    Vue.use(VueResource);
    Vue.http.interceptors.push((req, next) => {
      console.log("发送请求前拦截...");
      console.log(req);
      next(res => {
        console.log("收到响应结果后拦截...");
        console.log(res);
      })
    });
    var vm = new Vue({
      el: "#app",
      mounted() {
        //1.get不带参数
        this.$http
          .get("http://localhost:8080/index")
          .then(function (response) {
            console.log("response1:");
            console.log(response);
            console.log(response.data);
          });
        //2.get带参数的
        this.$http
          .get("http://localhost:8080/details", {
            params: {
              lid: 5
            }
          })
          .then(response => {
            console.log("response2:");
            console.log(response);
            console.log(response.data);
          });
        //3.post
        this.$http
          // .post("http://localhost:8080/user/login", {
          //   uname: "dingding",
          //   upwd: 123456
          // })
          .post("http://xzserver.applinzi.com/users/signin", {
            uname: "dingding",
            upwd: 123456
          })
          .then(response => {
            console.log("response3:");
            console.log(response);
            console.log(response.data);
          });
      }
    })
  </script>
</body>

</html>